package com.gan.simple_init.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gan.simple_init.model.sys.entity.SysMenu;
import com.gan.simple_init.model.sys.vo.SysMenuVO;
import com.gan.simple_init.service.SysMenuService;
import com.gan.simple_init.mapper.SysMenuMapper;
import com.gan.simple_init.util.UserCacheUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author gbw
* @description 针对表【sys_menu(菜单表)】的数据库操作Service实现
* @createDate 2023-08-11 14:47:38
*/
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu>
    implements SysMenuService{

    @Resource
    SysMenuMapper sysMenuMapper;

    @Resource
    UserCacheUtil userCacheUtil;


    @Override
    public List<SysMenuVO> selectMenuByUserId() {
        long userId = userCacheUtil.getUserId();
        // 管理员获得所有权限
        if (userCacheUtil.isAdmin()){
            return sysMenuMapper.selectAllMenu();
        }
        return sysMenuMapper.selectMenuByUserId(userId);
    }
}




